Skip to content

Implement draggable shapes #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 22, 2016
Merged

Conversation

n-riesco
Copy link
Contributor


Resubmitted PR after:

  • removing console.log from tests,
  • and checking tests pass locally with both Chromium and Firefox.

@n-riesco
Copy link
Contributor Author

I've run the tests locally using the CircleCI configuration (node_modules/.bin/karma start test/jasmine/karma.ciconf.js "tests/shapes_test.js") and they pass.

Any ideas how I can reproduce the failures locally?

n-riesco added 2 commits June 17, 2016 21:44
* Workaround to failure in CircleCI.
@n-riesco
Copy link
Contributor Author

I can reproduce the issue locally by using Firefox 38.0.

@n-riesco
Copy link
Contributor Author

I've fixed the failures in CircleCI!!!
The PR is ready for review.

.selectAll('path[data-index="' + index + '"')
.node();
return d3.selectAll('.shapelayer path').filter(function() {
return +this.getAttribute('data-index') === index;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Nice find @n-riesco !

@n-riesco
Copy link
Contributor Author

n-riesco commented Jun 21, 2016

TODO

  • test shape resize
  • update cursor onmousemove

}
}

function setupDragElement(gd, shapePath, shapeOptions, index) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this. Way to flatten the code. Thanks!

n-riesco added 4 commits June 22, 2016 11:01
* Defined a test case per direction, because a test case for all
  directions would timeout before completion.
* Update cursor before drag/resize interactions starts, so that the
  user knows what interactions will be initiated on click.
* The move drag area may be hidden if a shape is partially visible. In
  these circumstance users could only resize a shape.

* With this commit, users can press the shift key to move a shape
  regardless of the point where they click.
@n-riesco
Copy link
Contributor Author

I've been thinking of an algorithm to resize path shapes. Here's a simple proposal:

  • scale the x coordinate by a factor of 1 + dx/element.getBoundingClientRect.width
  • scale the y coordinate by a factor of 1 + dy/element.getBoundingClientRect.height
  • limit the scale down element.getBoundingClientRect.width - dx > MINWIDTH
  • limit the scale down element.getBoundingClientRect.height - dy > MINHEIGHT

x = evt.clientX - dragBBox.left,
y = evt.clientY - dragBBox.top,
cursor = (w > MINWIDTH && h > MINHEIGHT) ?
dragElement.getCursor(x / w, 1 - y / h) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done here.


dragElement.init(dragOptions);

function updateDragMode(evt) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. We should add a setCursor handler for annotations too.

That will deserve a PR of it own. Ticket here: #679

@etpinard
Copy link
Contributor

etpinard commented Jun 22, 2016

@n-riesco shapes referenced to date axes currently support date string (e.g '2016-06-22') and timestamps (e.g (new Date(2016, 5, 22).getTime()). See example: http://codepen.io/etpinard/pen/oLYEGN

But with { editable: true } dragging the timestamp shape results in

image

on line

image

@n-riesco
Copy link
Contributor Author

@etpinard Thx for catching that one! I've just pushed a fix and updated the tests to use both date strings and timestamps.

return function(v) { return convertToPx(v.replace('_', ' ')); };
return function(v) {
if(v.replace) v = v.replace('_', ' ');
return convertToPx(v);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@etpinard
Copy link
Contributor

Great PR. Thanks @n-riesco 🍻

moveFn: function(dx, dy) {
if(shapeOptions.type === 'path') {
var moveX = function moveX(x) { return p2x(x2p(x) + dx); };
if(xa && xa.type === 'date') moveX = encodeDate(moveX);
Copy link

@yogat3ch yogat3ch May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @etpinard,
Is it possible to constrain the drag direction to the x or y plane based on an option value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants